/*------------------------------------
Description:
	Buffer to of store a matrix line or column on IDCT-1D. The data should be send
	by the ram memory and stored before be send to arithmetics operations.
	A new value can be set each clock setup, and the release_data signal should be
	activated whith an interval one clock pulse, since last value is sent.
-------------------------------------*/
module idct_buffer
#(parameter DATA_WIDTH=16, parameter ADDR_WIDTH=8)
(
	input clk, reset, release_data, en,
	input [ADDR_WIDTH-1:0] addr,
	input [DATA_WIDTH-1:0] data,
	output reg [DATA_WIDTH-1:0] reg_1, reg_2, reg_3, reg_4, reg_5, reg_6, reg_7, reg_8
);

	reg [DATA_WIDTH-1:0] buffer[ADDR_WIDTH-1:0];
	
	always@(posedge clk or posedge reset) begin
		if(reset) 
		begin
			buffer[0] = 0;
			buffer[1] = 0;
			buffer[2] = 0;
			buffer[3] = 0;
			buffer[4] = 0;
			buffer[5] = 0;
			buffer[6] = 0;
			buffer[7] = 0;
		end 
		else if(en) 
		begin
			case(addr)
				0 : buffer[0] = data;
				1 : buffer[1] = data;
				2 : buffer[2] = data;
				3 : buffer[3] = data;
				4 : buffer[4] = data;
				5 : buffer[5] = data;
				6 : buffer[6] = data;
				7 : buffer[7] = data;
			endcase	
		end
		else if(release_data) begin
			reg_1 = buffer[0];
			reg_2 = buffer[1];
			reg_3 = buffer[2];
			reg_4 = buffer[3];
			reg_5 = buffer[4];
			reg_6 = buffer[5];
			reg_7 = buffer[6];
			reg_8 = buffer[7];
		end	/*else
		begin
			reg_1 = 0;
			reg_2 = 0;
			reg_3 = 0;
			reg_4 = 0;
			reg_5 = 0;
			reg_6 = 0;
			reg_7 = 0;
			reg_8 = 0;				
		end*/			
	end
	
endmodule
